package com.ruoyi.hualian.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hualian.domain.HlMaterial;
import com.ruoyi.hualian.service.IHlMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 材质Controller
 * 
 * @author hujian
 */
@RestController
@RequestMapping("/hualian/material")
public class HlMaterialController extends BaseController
{
    @Autowired
    private IHlMaterialService hlMaterialService;

    /**
     * 查询材质列表
     */
    @PreAuthorize("@ss.hasPermi('hualian:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(HlMaterial hlMaterial)
    {
        startPage();
        List<HlMaterial> list = hlMaterialService.selectHlMaterialList(hlMaterial);
        return getDataTable(list);
    }

    /**
     * 导出材质列表
     */
    @PreAuthorize("@ss.hasPermi('hualian:material:export')")
    @Log(title = "材质", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HlMaterial hlMaterial)
    {
        List<HlMaterial> list = hlMaterialService.selectHlMaterialList(hlMaterial);
        ExcelUtil<HlMaterial> util = new ExcelUtil<HlMaterial>(HlMaterial.class);
        util.exportExcel(response, list, "材质数据");
    }

    /**
     * 获取材质详细信息
     */
    @PreAuthorize("@ss.hasPermi('hualian:material:query')")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        return success(hlMaterialService.selectHlMaterialByMaterialId(materialId));
    }

    /**
     * 新增材质
     */
    @PreAuthorize("@ss.hasPermi('hualian:material:add')")
    @Log(title = "材质", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HlMaterial hlMaterial)
    {
        return toAjax(hlMaterialService.insertHlMaterial(hlMaterial));
    }

    /**
     * 修改材质
     */
    @PreAuthorize("@ss.hasPermi('hualian:material:edit')")
    @Log(title = "材质", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HlMaterial hlMaterial)
    {
        return toAjax(hlMaterialService.updateHlMaterial(hlMaterial));
    }

    /**
     * 删除材质
     */
    @PreAuthorize("@ss.hasPermi('hualian:material:remove')")
    @Log(title = "材质", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(hlMaterialService.deleteHlMaterialByMaterialIds(materialIds));
    }
}
